package com.nbjtjc.safe.mapper.edu;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.nbjtjc.safe.model.edu.EduRequirementItemsSurveyResults;
import com.nbjtjc.util.MyMapper;
@Mapper
public interface EduRequirementItemsSurveyResultsMapper extends MyMapper<EduRequirementItemsSurveyResults> {
	@Delete("delete from edu_requirement_items_survey_results where user_survey_result_id = #{userSurveyResultId}")
	int  deleteByUserSurveyResultId(@Param("userSurveyResultId") Integer userSurveyResultId);
	
//	@Insert("INSERT INTO edu_requirement_items_survey_results(req_invest_id,user_survey_result_id,user_id,department,items_id,items) (SELECT #{reqInvestId} AS req_invest_id,a.id AS user_survey_result_id,a.user_id,a.department,b.id AS items_id,b.items AS items  FROM edu_requirement_user_survey_results a,edu_requirement_survey_item b  WHERE a.req_invest_id = #{reqInvestId} AND b.req_invest_id = #{reqInvestId})")
	@Insert("INSERT INTO edu_requirement_items_survey_results(user_survey_result_id,items_id,items) (SELECT a.id AS user_survey_result_id,b.id AS items_id,b.items AS items  FROM edu_requirement_user_survey_results a,edu_requirement_survey_item b  WHERE a.req_invest_id = #{reqInvestId} AND b.req_invest_id = #{reqInvestId})")
	int createItemsResult(@Param("reqInvestId") int reqInvestId);
	
	@Select("select a.* from edu_requirement_items_survey_results a where a.user_survey_result_id = #{userSurveyResultId}")
	List<EduRequirementItemsSurveyResults>   findByUserSurveyResultId(@Param("userSurveyResultId") int userSurveyResultId);

	@Select("SELECT COUNT(*) FROM edu_requirement_user_survey_results WHERE req_invest_id = #{reqId} AND `status` = 1")
	int totalRespondent(@Param("reqId")Integer id);
}